package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class FileController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    /**
     * 文件上传
     *
     * @param image
     * @return
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile image) {
        try {
            String url = aliOSSUtils.upload(image);
            return Result.success(url);
        } catch (IOException e) {
            return Result.error("上传失败");
        }

    }
}